<template>
	<view>
		<view class="shop_index_bj">
			<view class="flex j-s a-c did">
				<!-- 			<view v-if="itype==1">
					<text style="color: #fff;font-size: 35rpx;">{{set.shop_name}}</text>
				</view> -->
				<view class="flex a-c j-b pl3 pr3 ml2" v-if="itype==1"
					style="background-color:#fff;height: 80rpx;border-radius: 36rpx;flex: 1;">
					<input v-model="busName" type="text" class="f26" placeholder="输入商家名称">
					<text @click="on_tab(tabindex,platform,1)" class="w800 f30 ml1" style="color: #0071FE;">搜索</text>
				</view>
			</view>
			<swiper class="swiper" circular :indicator-dots="fasle" :autoplay="true" :interval="3000"
				indicator-color="rgba(238, 238, 238, 0.1)">
				<swiper-item v-for="(item,index) in publise">
					<image @click="jumpUrl(item.url)" :src="item.pic" mode="aspectFill" style="width: 100%;height:100%;">
					</image>
				</swiper-item>
			</swiper>

		</view>
		<!-- 	<view class="p2" style="margin-top: -60rpx;">
			<view class="flex a-c j-c" style="background-color: #fff;height: 80rpx;border-radius: 15rpx;">
				<text></text>
		<text style="color: #0071FE;">{{statistics.shop_read}}</text>
				<text style="margin-left: 100rpx;">已入驻商家:</text>
				<text style="color: #0071FE;">{{statistics.shop_num}}</text>
			</view>
		</view> -->

		<view class=" p20">
			<view class="row-wrap b_y pb2" style="background-color: #fff;">
				<view style="width: 140rpx;" v-for="(vo, index) in NavList" :key="index">
					<view style="padding-top:20rpx;text-align: center;" @click="on_index(vo.id,index)">
						<image :src="vo.url" style="width:80rpx;height:80rpx;">
						</image>
						<view class="pt1">
							<text style="font-size: 26rpx;">{{vo.text}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="pl2 pr2"
			style="position: -webkit-sticky; position: sticky;top: 0px;z-index: 10;background-color: #fff;">
			<view v-if="itype==1" class="flex j-s a-c p20 bb" style="background-color: #fff;">
				<text @click="on_tab(0,'',1)" :class="tabindex==0 ? 'tab_list' : 'tab_list_w'">附近商家</text>
				<text @click="on_tab(1,1,1)" :class="tabindex==1 ? 'mtse' : 'tab_list_w'">只看美团</text>
				<text @click="on_tab(2,2,1)" :class="tabindex==2 ? 'elm' : 'tab_list_w'">只看饿了么</text>
			</view>
			<view v-if="itype==2" class="flex j-s a-c p20 bb" style="background-color: #fff;">
				<text @click="on_tab(0,false,2)" :class="tabindex==0 ? 'tab_list' : 'tab_list_w'">待完成</text>
				<text @click="on_tab(1,true,2)" :class="tabindex==1 ? 'tab_list' : 'tab_list_w'">已完成</text>
			</view>
			<view v-if="itype==3" class="flex j-s a-c p20 bb" style="background-color: #fff;">
				<text @click="on_tab(0,false,2)" :class="tabindex==0 ? 'tab_list' : 'tab_list_w'">待审核商户</text>
				<!-- <text @click="on_tab(1,true,2)" :class="tabindex==1 ? 'tab_list' : 'tab_list_w'">已完成</text> -->
			</view>
		</view>
		<!-- <image src="../../static/zd.png" mode="aspectFill" class="zd"></image> -->
		<!-- 管理员审核列表 -->
		<auditlist v-if="itype==3" :list="shop_list" :islog="islog" :log="log" :tabindex="tabindex"></auditlist>
		<!-- 用户列表 -->
		<shopList v-if="itype==1" :list="shop_list" :islog="islog" :log="log" :tabindex="tabindex"> </shopList>
		<!-- 商家列表 -->
		<shopindex v-if="itype==2" :list="shop_list" :islog="islog" :log="log" :tabindex="tabindex"> </shopindex>
	</view>
</template>

<script>
	import shopList from "@/zu/ban_tongchengshop/shop_list.vue";
	import shopindex from "@/pages/list/shop_index.vue";
	import auditlist from "@/pages/list/auditlist.vue";
	export default {
		components: {
			shopList,
			shopindex,
			auditlist
		},
		data() {
			return {
				publise: [],
				totalPage: null,
				itype: 1,
				isFinish: false,
				set: {},
				NavList: [],
				// NavList: [{
				// 		text: '群',
				// 		url: '../../static/tab/pt.png'
				// 	},
				// 	{
				// 		text: '新手指引',
				// 		url: '../../static/tab/pt.png'
				// 	},
				// 	{
				// 		text: '客服',
				// 		url: '../../static/tab/kf.png'
				// 	},
				// 	{
				// 		text: '客服',
				// 		url: '../../static/tab/kf.png'
				// 	},
				// 	{
				// 		text: '客服',
				// 		url: '../../static/tab/kf.png'
				// 	}
				// ],
				statistics: {},
				shop_list: [],
				tabindex: 0,
				islog: true,
				log: '加载中',
				limit: 10,
				page: 1,
				platform: '', //1为美团、2为饿了么--、3为两家都有
				busName: ''
			}
		},
		onShow() {
			this.publis() //公参
			if (!uni.getStorageSync('user')) {
				this.itype = 1
			} else {
				this.itype = uni.getStorageSync('user').itype
			}
			this.page = 1;
			var that = this;
			uni.getLocation({ //获取位置信息
				type: 'gcj02',
				success: function(res) {
					uni.setNavigationBarTitle({
						title: '花着省'
					});
					that.latitude = res.latitude //纬度
					that.longitude = res.longitude //经度
					uni.setStorageSync('latitude', res.latitude);
					uni.setStorageSync('longitude', res.longitude);
					that.shop_init();
				},
				fail: error => {
					this.$module.showToast('定位未开启,请手动开启')
					uni.setStorageSync('latitude', '');
					uni.setStorageSync('longitude', '');
					this.isinit = false;
					this.islog = false;
				}
			});
		},
		onLoad(item) {
			uni.setStorageSync('inviteUserId', item.id)
		},
		onShareAppMessage(res) {
			return {
				title: '',
				path: `/pages/index/index?id=${uni.getStorageSync("user").id || ""}`,
				imageUrl: 'https://bige.cdn.bcebos.com/designs/covers/2009/hAh2Qh6sh280.jpg',
			}
		},

		onShareTimeline(res) {
			return {
				title: '',
				path: `/pages/index/index?id=${uni.getStorageSync("user").id || ""}`,
				imageUrl: '',
			}
		},
		methods: {
			jumpUrl(url) { //跳转的地址
				this.$module.navigateTo('/pages/views/webview?url=' + url)
			},
			on_index(id, index) {
				var type = this.NavList[index]['type'];
				if (type == 1) {
					this.tao(this.NavList[index]['appId'], this.NavList[index]['path']);
					return
				}
				uni.navigateTo({
					url: '/pages/ban_tongchengshop/nav_list?id=' + id
				})
			},
			// on_search() {
			// 	uni.navigateTo({
			// 		url: '/pages/ban_tongchengshop/shop_search?search_key=' + this.search_key
			// 	})
			// },
			// on_index(id) {
			// 	uni.navigateTo({
			// 		url: '/pages/ban_tongchengshop/nav_list?id=' + id
			// 	})
			// },
			on_tab(index, platform, type) { //搜索
				this.shop_list = [];
				this.islog = true;
				this.page = 1;
				this.log = '加载中';
				if (type == 1) {
					this.platform = platform;
					this.tabindex = index;
					this.shop_init();
				} else if (type == 2) {
					this.isFinish = platform;
					this.tabindex = index;
					this.shop_init();
				} else {
					return
				}
			},
			publis() { //查询用户信息
				var that = this;
				this.Htpp.publi().then(ret => {
					this.$module.sm(ret, 2, res => {
						uni.setStorageSync('publis', res.data) //公共参数 消费多少
						this.publise = uni.getStorageSync('publis').activityPictures
					})
				})
			},
			shop_init() { //获取首页数据列表
				var that = this;
				let data = {
					data
				}
				let requestParams = {
					limit: this.limit,
					page: this.page,
					latitude: this.latitude,
					longitude: this.longitude,
					busName: this.busName,
					platform: this.platform || null, //商家类型（美团、饿了么）
					isFinish: this.isFinish, //是否是已完成活动
					// businessId: uni.getStorageSync('business').id || null
					businessId: uni.getStorageSync('user').id || null
				};
				this.$module.sm(requestParams, 1, res => {
					data.data = res
				})
				this.Htpp.post(this.itype == 1 ? '/mehrb/login/user/page' : (this.itype == 2 ? '/mehrb/meplus/activity/page' :
					'/mehrb/meplus/business/page'), 'app', {
					datalist: data
				}).then(ret => {
					that.$module.sm(ret, 2, res => {
						this.totalPage = res.data.totalPage
						if (that.page == 1) {
							this.shop_list = res.data.list;
						} else {
							if (res.data.list.length > 0) {
								for (var i = 0; i < res.data.list.length; i++) {
									that.shop_list.push(res.data.list[i]);
								}
							}
							if (res.data.list.length < 10) {
								this.log = "没有数据了"
								return
							}
						}
						setTimeout(() => {
							that.isinit = false;
							that.islog = false;
						}, 100)
					})
				})
			},
		},
		onReachBottom() {
			this.jiazai = "加载中...";
			this.page += 1;
			if (this.page > this.totalPage) {
				this.$module.showToast("已经到底了")
				return
			} else {
				this.shop_init()
			}
		},
	}
</script>
<style lang="less">
	.swiper {
		height: 300rpx;
	}

	.zd {
		position: fixed;
		right: 40rpx;
		bottom: 100rpx;
		width: 100rpx;
		height: 100rpx;
	}

	.tab_list {
		font-weight: 800;
		border-bottom: solid 5rpx #0071FE;
		padding-bottom: 10rpx;
		color: #0071FE;
	}

	.mtse {
		font-weight: 800;
		border-bottom: solid 5rpx #FDC400;
		padding-bottom: 10rpx;
		color: #FDC400;
	}

	.elm {
		font-weight: 800;
		border-bottom: solid 5rpx #0192FF;
		padding-bottom: 10rpx;
		color: #0192FF;
	}

	.tab_list_w {
		border-bottom: solid 5rpx #fff;
		padding-bottom: 10rpx;
		color: #7B7B7B;
	}

	.yuanzi {
		background-color: #F6F7FB;
		margin: 2px;
		padding-right: 5px;
		padding-left: 5px;
		padding-top: 2px;
		padding-bottom: 2px;
		font-size: 10px;
		color: #707072;
		border-radius: 12px;
	}

	.shop_index_bj {
		/* position: sticky; */
		position: relative;
		right: 0;
		left: 0;
		width: 100%;

		.did {
			z-index: 999;
			position: absolute;
			top: 30rpx;
			margin: 0 auto;
			left: 30rpx;
			right: 30rpx;
			opacity: 0.7;
		}
	}
</style>